/*业务工具*/

(function(factory){
    if(typeof define==="function" && define.amd){
        define([
            'jquery',
            'fly'
        ],factory);
    }else{
        factory(jQuery);
    }
})(function ($,fly){
    var originWin=window.parent;
    var util=fly.utils;

    //dao 方法
    var dao={
        /*根据申报号获取流程实例ID*/
        getInstIdByProjNo:function(data){
            var obj=new util.ajaxObj(),
                options=$.extend({},obj.options);
            options.before();
            util.ajax.post('proItem/getPreApasinfo.do',data,'text')
                .done(function(data){
                    data=util.toObj(data);
                    setTimeout(function(){
                        options.after();
                        obj._done && obj._done(data);
                    },0)
                }).fail(function(){
                    setTimeout(function(){
                        options.after();
                        obj._fail && obj._fail();
                    },0)
            });
            return obj;
        },
        //根据出生日期计算年龄
        getAgeByBirth:function(birth){
            var year1=(new Date()).getFullYear(),
                year2=birth.substr(0,4);
            return year1-year2;
        },
        //返回指定格式的出生日期
        getFormatBirth:function(format,birth){
            switch (format){
                case 'yyyy-mm':
                    return birth.substr(0,7);
                    break;
                default:
                    return birth;
                    break;
            }
        },
        //去除表单查询条件的首位空格
        trimSpace:function(originOptions){
            var trimOptions={},
                index;
            for(index in originOptions){
                if(typeof originOptions[index]!='number'){
                    trimOptions[index]=$.trim(originOptions[index])
                }else{
                    trimOptions[index]=originOptions[index];
                }
            };
            return trimOptions;
        },
        //通过身份证获取年龄
        getAge:function(idCard){
            var year1;
            idCard=$.trim(idCard)
            if(idCard.length==15){
                year1=Number('19'+idCard.substring(6,8));
            }else if(idCard.length==18){
                year1=Number(idCard.substring(6,10));
            }else{
                return null;
            }
            var year2=(new Date()).getFullYear();
            return (year2-year1);
        },
        //通过身份证获取性别
        getSex:function(idCard){
            idCard=$.trim(idCard);
            if(idCard.length==15){
                if(idCard.substring(14,15)%2==0){
                    return "女";
                }else{
                    return "男";
                }
            }else if(idCard.length==18){
                if(idCard.substring(14,17)%2==0){
                    return "女";
                }else{
                    return "男";
                }
            }else{
                return null;
            }
        },
        //通过身份证获取出生日期
        getBirth:function(idCard){
            idCard=$.trim(idCard);
            if(idCard.length==15){
                var year=idCard.substring(6,8);
                var month=idCard.substring(8,10);
                var day=idCard.substring(10,12);
                return "19"+year+"-"+month+"-"+day;
            }else if(idCard.length==18){
                var year = idCard.substring(6, 10);
                var month = idCard.substring(10, 12);
                var day = idCard.substring(12, 14);
                return year + '-' + month + '-' + day;
            }else{
                return null;
            }
        },
        //获取两日期相差天数
        dateDiff:function(sDate1,sDate2){
            var aDate,oDate1,oDate2,iDays;
            aDate=sDate1.split("-")
            oDate1=new Date(aDate[1]+'-'+aDate[2]+'-'+aDate[0])
            aDate=sDate2.split("-")
            oDate2=new Date(aDate[1]+"-"+aDate2[2]+'-'+aDate[0])
            iDays=parentInt(Math.abs(oDate1-oDate2)/1000/60/60/24)
            return iDays;
        }
    }
})